<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>scroll-progress-bar</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            min-height: 200vh;
        }
        .scroll-progress-bar {
            width: 0%;
            position: fixed;
            top: 0;
            left: 0;
            height: 4px;
            background: linear-gradient(135deg,#b3d5f7 10%,#9643e9 90%);
            z-index: 10000;
        }
    </style>
</head>
<body>
    <div class="scroll-progress-bar" id="scroll-progress-bar"></div>
    <p>滚动查看</p>
    <script>
        const scrollBar = document.getElementById('scroll-progress-bar');
        const height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
        window.addEventListener('scroll',() => {
            const scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
            scrollBar.style.width = `${(scrollTop / height) * 100}%`;
        })
    </script>
</body>
</html>